package gui;

import client.Requests;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author Sasa
 */
public class AddMember {

    public Boolean isMember = false;

    public Requests req;
    public JFrame f;
    public JPanel jPanelUser;
    public JLabel jLabelUser;
    public JPanel jPanelPass;
    public JLabel jLabelPass;


    public JPanel jPanelLogin;
    public JSeparator jSeparator1;


    public AddMember(Requests req) {
        this.req = req;
        jPanelUser = new JPanel();
        jLabelUser = new JLabel();
        jPanelPass = new JPanel();
        jLabelPass = new JLabel();
        jPanelLogin = new JPanel();
        jSeparator1 = new JSeparator();

        f = new JFrame("Collab - New Member");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setBounds(new Rectangle(400, 200, 335, 175));
        f.setResizable(false);
        f.setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));

        jPanelUser.setLayout(new FlowLayout(FlowLayout.LEFT));

        jLabelUser.setFont(new Font("Verdana", 1, 14));
        jLabelUser.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabelUser.setText("Username:");
        jLabelUser.setHorizontalTextPosition(SwingConstants.LEADING);
        jLabelUser.setMaximumSize(new Dimension(100, 20));
        jLabelUser.setMinimumSize(new Dimension(100, 20));
        jLabelUser.setPreferredSize(new Dimension(100, 20));
        jPanelUser.add(jLabelUser);

        final JTextField jTextFieldUser = new JTextField();
        jTextFieldUser.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jTextFieldUser.setMargin(new java.awt.Insets(1, 5, 1, 1));
        jTextFieldUser.setMaximumSize(new java.awt.Dimension(200, 40));
        jTextFieldUser.setMinimumSize(new java.awt.Dimension(200, 40));
        jTextFieldUser.setPreferredSize(new java.awt.Dimension(200, 40));
        jPanelUser.add(jTextFieldUser);

        f.getContentPane().add(jPanelUser);

        jPanelPass.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabelPass.setFont(new java.awt.Font("Verdana", 1, 14));
        jLabelPass.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelPass.setText("Password:");
        jLabelPass.setMaximumSize(new java.awt.Dimension(100, 20));
        jLabelPass.setMinimumSize(new java.awt.Dimension(100, 20));
        jLabelPass.setPreferredSize(new java.awt.Dimension(100, 20));
        jPanelPass.add(jLabelPass);

        final JPasswordField jTextFieldPass = new JPasswordField();
        jTextFieldPass.setFont(new java.awt.Font("Tahoma", 0, 24));
        jTextFieldPass.setMargin(new java.awt.Insets(1, 5, 1, 1));
        jTextFieldPass.setMaximumSize(new java.awt.Dimension(200, 40));
        jTextFieldPass.setMinimumSize(new java.awt.Dimension(200, 40));
        jTextFieldPass.setPreferredSize(new java.awt.Dimension(200, 40));
        jPanelPass.add(jTextFieldPass);

        f.getContentPane().add(jPanelPass);
        f.getContentPane().add(jSeparator1);

        JButton jButtonLogin = new JButton("Add new member");
        jButtonLogin.setText("Login");
        jPanelLogin.add(jButtonLogin);

        f.getContentPane().add(jPanelLogin);

        jButtonLogin.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    reqAddMember(jTextFieldUser.getText(), jTextFieldPass.getText());
                } catch(Exception e) {
                    System.out.println(e);
                }
            }
        });
        
        f.setVisible(true);
    }

    public void reqAddMember(String usr, String psw) throws Exception {
        this.req.newMember(usr, psw);
	f.dispose();
	f.setVisible(false);
    }
}
